

using UnityEngine;


[AddComponentMenu("Utils/RenderQueueOverride")]
[ExecuteInEditMode]
public class RenderQueueOverride : MonoBehaviour
{
    [SerializeField]
    int m_RenderQueue = 2000;

#if UNITY_EDITOR // do it every frame in editor so param modifications are immediately visible

    void LateUpdate()
    {
        SetParam();
    }

#else // but do it just once in standard app
	
	void Awake()
	{
		SetParam();
	}
	
#endif

    void SetParam()
    {
        var rs = GetComponentsInChildren<Renderer>();
        if (rs != null)
        {
            foreach (var r in rs)
            {
                foreach (var m in r.sharedMaterials)
                {
                    if (m != null)
                    {
                        m.renderQueue = m_RenderQueue;
                    }
                }
            }
        }
    }
}

